﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EvoGame.Bitmaps;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace EvoGame.World
{
    class Tile : GameObject.GameObject
    {
        bool solid;
        public Vector2 pos;
        public Texture2D texture;

        public Tile(int id, string name, Texture2D texture, Vector2 pos)
            :base(texture, pos)
        {
            this.id = id;
            this.name = name;
            this.pos = pos;
            this.texture = texture;
            Game1.tiles.Add(this);
        }

        public void setPos(Vector2 pos, int times = 17)
        {
            pos = new Vector2(pos.X * times, pos.Y * times);
        }

        public void setTexture(Texture2D tex)
        {
            texture = tex;
        }

        public static string GetTileNameById(int id)
        {
            foreach (Tile tile in Game1.tiles)
            {
                if (tile.id == id)
                    return tile.name;
            }
            return null;
        }

        public static int GetTileIdByName(string name)
        {
            foreach (Tile tile in Game1.tiles)
            {
                if (tile.name == name)
                    return tile.id;
            }
            return 0;
        }

        public int id;

        public string name;

        public bool IsSolid
        {
            get { return solid; }
            set { solid = value; }
        }

        public Rectangle BoundingBox
        {
            get
            {
                return new Rectangle(
                    (int)Position.X,
                    (int)Position.Y,
                    texture.Width,
                    texture.Height);
            }
        }
    }
}
